package com.duomai.myapplication;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.duomai.myapplication.base.BaseActivity;
import com.duomai.myapplication.frament.UserHomeFragment;
import com.duomai.myapplication.frament.UserMineFragment;
import com.example.admin.SQLite.User;
import com.orhanobut.hawk.Hawk;

public class MainActivity extends BaseActivity {
    LinearLayout llTab1;
    LinearLayout llTab2;
    TextView tvTab1, tvTab2,tvTile;

    @Override
    public void setContentView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
        User user= Hawk.get("user");

        tvTile = findViewById(R.id.tvTile);
        tvTile.setText(user.UserAddress);
        llTab1 = findViewById(R.id.llTab1);
        llTab2 = findViewById(R.id.llTab2);
        tvTab1 = findViewById(R.id.tvTab1);
        tvTab2 = findViewById(R.id.tvTab2);
        tvTab1.setTextColor(Color.BLACK);
        tvTab2.setTextColor(Color.GRAY);
        addFragments(new UserHomeFragment());
        llTab1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvTab1.setTextColor(Color.BLACK);
                tvTab2.setTextColor(Color.GRAY);
                addFragments(new UserHomeFragment());
            }
        });
        llTab2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tvTab2.setTextColor(Color.BLACK);
                tvTab1.setTextColor(Color.GRAY);
                addFragments(new UserMineFragment());
            }
        });
    }

    @Override
    public void setInitView() {

    }

    private void addFragments(Fragment fragment) {
        FragmentManager manager = getSupportFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.contenLayout, fragment);
        transaction.commit();
    }
}